package cnpm.dao.impl;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import cnpm.dao.LiteracyDAO;
import cnpm.entity.Literacy;
import cnpm.util.HibernateUtil;

public class LiteracyDAOImpl implements LiteracyDAO {

	private SessionFactory sessionFactory;
	private Session session;
	
	public LiteracyDAOImpl() {
		sessionFactory = HibernateUtil.getSessionFactory();
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Literacy> getAllLiteracy() {
		List<Literacy> list=null;
		try{
			session = sessionFactory.openSession();
			list = (List<Literacy>) session.createCriteria(Literacy.class).list();
		}catch(HibernateException e){
			e.printStackTrace();
		}finally{
			session.close();
		}
		return list;	}

	@Override
	public Literacy getLiteracyByID(int literacyID) {
		Literacy literacy = null;
		try{
			session = sessionFactory.openSession();
			literacy = (Literacy) session.get(Literacy.class, literacyID);
		}catch(HibernateException e1){
			e1.printStackTrace();
		}finally{
			session.close();
		}
		return literacy;
	}

}
